package com.v1.video.db.service;

import java.util.List;

import com.v1.video.AppContext;
import com.v1.video.db.dao.RecommendTB;
import com.v1.video.db.dao.RecommendTBDao;
import com.v1.video.dbcore.greenrobot.dao.query.QueryBuilder;

public class RecommendDB {

	private static RecommendDB mInstance;
	private RecommendTBDao mRecommendTBDao;

	private RecommendDB() {
		mRecommendTBDao = AppContext.getDaoSession().getRecommendTBDao();
	}

	public static RecommendDB getInstance() {
		if (mInstance == null) {
			mInstance = new RecommendDB();
		}
		return mInstance;
	}
	
	public void insertInTx(List<RecommendTB> entities) {
		mRecommendTBDao.insertInTx(entities);
	}
	
	public List<RecommendTB> getAllData() {
		QueryBuilder<RecommendTB> query = mRecommendTBDao.queryBuilder();
		return query.build().list();
	}
	
	public List<RecommendTB> getSingleData(int page, int rows) {
		QueryBuilder<RecommendTB> query = mRecommendTBDao.queryBuilder()
				.orderAsc(RecommendTBDao.Properties.Id).limit(rows)
				.offset(page * rows);
		return query.build().list();
	}
	
	public void deleteAll() {
		mRecommendTBDao.deleteAll();
	}
}
